package com.blank.dao.Impl;

import com.blank.dao.UserDao;
import com.blank.pojo.bo.User;
import com.blank.util.DButil;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author BLANK
 * @date 2020/11/16
 */
public class UserDaoImpl implements UserDao {
    @Override
    public boolean addUser(User user) throws SQLException {
        DButil dButil =new DButil();
        String sql="insert into t_user(username, password, usertype, update_by_user, update_by_last, create_by_user, create_by_time) VALUES (?,?,1,'system',now(),?,now())";
        PreparedStatement ps=dButil.getPreparedStatement(sql);
        ps.setString(1,user.getUsername());
        ps.setString(2,user.getPassword());
        ps.setString(3,user.getUsername());
    int i=ps.executeUpdate();
    if (i==1){
        dButil.commit();
        dButil.colserResoure();
        return  true;
    }
    dButil.connectionRollback();
    dButil.colserResoure();
        return false;
    }
}
